package com.kapcb.ruleengine.core;

import com.kapcb.ruleengine.api.Facts;
import com.kapcb.ruleengine.api.Rule;

import java.util.Collections;

/**
 * <a>Title: NaturalRules </a>
 * <a>Author: Kapcb <a>
 * <a>Description: NaturalRules <a>
 *
 * @author Kapcb
 * @version 1.0
 * @date 2024/8/17 10:24
 * @since 1.0
 */
public class NaturalRules extends CompositeRule {


    public static CompositeRule of(Rule... rules) {
        CompositeRule instance = new NaturalRules();
        Collections.addAll(instance.rules, rules);
        return instance;
    }

    @Override
    public boolean evaluate(Facts facts) {
        // 不支持, which means Natural Rules can not be the children of other rules
        throw new RuntimeException("evaluate not supported for natural composite");
    }

    @Override
    public void execute(Facts facts) {
        // 不支持, which means Natural Rules can not be the children of other rules
        throw new RuntimeException("execute not supported for natural composite");
    }

    @Override
    protected boolean doApply(Facts facts) {
        for (Rule rule : rules) {
            rule.apply(facts);
        }
        return true;
    }

}
